package co.edu.unal.satacredito.rest.representations.general;

import java.util.Date;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import co.edu.unal.satacredito.rest.domain.general.CardType;
import co.edu.unal.satacredito.rest.domain.general.DocumentType;
import co.edu.unal.satacredito.rest.domain.general.GenericTransaction;
import co.edu.unal.satacredito.rest.domain.general.ValidationResult;
import co.edu.unal.satacredito.rest.representations.Link;
import co.edu.unal.satacredito.rest.representations.Representation;
import co.edu.unal.satacredito.rest.representations.RestUri;

@XmlRootElement(name = "genericTransaction")
public class GenericTransactionRepresentation extends Representation {

	@XmlElement
	private String personName;

	@XmlElement
	private String document;

	@XmlElement
	private DocumentType documentType;

	@XmlElement
	private String cardNumber;

	@XmlElement
	private String cardCode;

	@XmlElement
	private CardType cardType;

	@XmlElement
	private Date cardDate;

	@XmlElement
	private String bank;

	@XmlElement
	private Integer franchise;

	@XmlElement
	private Date purchaseDate;

	@XmlElement
	private Float purchaseAmount;

	@XmlElement
	private String purchaseDetail;

	@XmlElement
	private Date validationDate;

	@XmlElement
	private ValidationResult validationResult;

	@XmlElement
	private String validationMessage;

	GenericTransactionRepresentation() {
		// TODO Auto-generated constructor stub
	}

	public GenericTransactionRepresentation(
			GenericTransaction genericTransaction, Link... links) {

		this.personName = genericTransaction.getPersonName();
		this.document = genericTransaction.getDocument();
		this.documentType = genericTransaction.getDocumentType();
		this.cardNumber = genericTransaction.getCardNumber();
		this.cardCode = genericTransaction.getCardCode();
		this.cardType = genericTransaction.getCardType();
		this.cardDate = genericTransaction.getCardDate();
		this.bank = genericTransaction.getBank();
		this.franchise = genericTransaction.getFranchise();
		this.purchaseDate = genericTransaction.getPurchaseDate();
		this.purchaseAmount = genericTransaction.getPurchaseAmount();
		this.purchaseDetail = genericTransaction.getPurchaseDetail();
		this.validationDate = genericTransaction.getValidationDate();
		this.validationResult = genericTransaction.getValidationResult();
		this.validationMessage = genericTransaction.getValidationMessage();
		this.links = java.util.Arrays.asList(links);
	}

	public static GenericTransactionRepresentation createResponseRepresentation(
			GenericTransaction genericTransaction, RestUri uri) {
		return new GenericTransactionRepresentation(genericTransaction,
				new Link(Representation.SELF_REL_VALUE, uri));
	}

	public GenericTransaction getGenericTransaction() {
		GenericTransaction genericTransaction = new GenericTransaction(
				personName, document, documentType, cardNumber, cardCode,
				cardType, cardDate, bank, franchise, purchaseDate,
				purchaseAmount, purchaseDetail);

		genericTransaction.setValidationDate(validationDate);
		genericTransaction.setValidationMessage(validationMessage);
		genericTransaction.setValidationResult(validationResult);

		return genericTransaction;
	}
}